/*
 * Created on May 5, 2004
 *
 * Vectrics Inc.  GNU Public License.
 */
package org.vectrics.company;


import org.vectrics.common.db.Criteria;
import org.vectrics.hibernate.Filter;
import org.vectrics.user.Person;

/**
 * @author mmoore
 */
public class CompanySelectCriteria extends Criteria {
	public static final long serialVersionUID = 98321591652129L;
	private Long parentId = null;
	private String name = null;
	private String city = null;
	private String state = null;
	private boolean noChildren = false;
	
	/**
	 * 
	 */
	public CompanySelectCriteria() {
		super();
		this.setVoidedType(CompanySelectCriteria.VOID_NO);
	}

	/**
	 * @return Returns the city.
	 */
	public String getCity() {
		return city;
	}

	/**
	 * @param city The city to set.
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return Returns the state.
	 */
	public String getState() {
		return state;
	}

	/**
	 * @param state The state to set.
	 */
	public void setState(String state) {
		this.state = state;
	}
	
	
	public void addConditionsToFilter(Filter filter, String tableObjectName) {
		if (this.getVoidedType() == Criteria.VOID_NO)
			filter.addParameterCondition(tableObjectName + ".voided", "=", "F");
		
		if (this.getVoidedType() == Criteria.VOID_YES)
			filter.addParameterCondition(tableObjectName + ".voided", "=", "T");
		
		if (this.getParentId() != null) {
			filter.addParameterCondition(tableObjectName + ".parent.id", "=", this.getParentId());
		} else if (this.getNoChildren()) {
			filter.addCondition(tableObjectName + ".parent.id is null");
		}
		if ((this.getName() != null) && (this.getName().trim().length() > 0)) {
			filter.addStringCondition(tableObjectName + ".name", this.getName());
		}

		if ((this.getCity() != null) && (this.getCity().trim().length() > 0)) {
			filter.addStringCondition(tableObjectName + ".address.city", this.getCity());
		}

		if ((this.getState() != null) && (this.getState().trim().length() > 0)) {
			filter.addStringCondition(tableObjectName + ".address.state", this.getState());
		}
	}
	

	/**
	 * @return Returns the parentId.
	 */
	public Long getParentId() {
		return parentId;
	}

	/**
	 * @param parentId The parentId to set.
	 */
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	/**
	 * @return Returns the noChildren.
	 */
	public boolean getNoChildren() {
		return noChildren;
	}

	/**
	 * @param noChildren The noChildren to set.
	 */
	public void setNoChildren(boolean noChildren) {
		this.noChildren = noChildren;
	}


}
